 #include <QtGui>
 #include <QtOpenGL>
#include <QDebug>

 #include <math.h>

 #include "glwidget.h"

 #ifndef GL_MULTISAMPLE
 #define GL_MULTISAMPLE  0x809D
 #endif

 GLWidget::GLWidget(QWidget *parent)
     : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
 {
     setFixedSize(320, 320);
 }

 GLWidget::~GLWidget()
 {
 }

 void GLWidget::initializeGL()
 {
     glClearColor (1.0, 1.0, 1.0, 0.0);
     glMatrixMode (GL_PROJECTION);
     gluOrtho2D (0.0, 320.0, 0.0, 320.0);
 }

 void GLWidget::paintGL()
 {
     int i, j;
     glClear(GL_COLOR_BUFFER_BIT );
     glColor3f(cell.mask[0][0], 0, 0);
     glPointSize(2);
     for (i=0; i<cell.red.size(); i++)
     {
             for (j=0; j<cell.red[i].size(); j++)
             {
                     glBegin (GL_POINTS);
                             glColor3f (cell.red[i][j]/255, cell.green[i][j]/255, cell.blue[i][j]/255);
                             glVertex2i (j, 160-i);
                             glColor3f(cell.grey[i][j]/255.0,cell.grey[i][j]/255.0, cell.grey[i][j]/255.0);
                             glVertex2i (160+j, 160-i);
                             glColor3f (cell.mask[i][j], 0, 0);
                             glVertex2i (j, 320-i);
                     glEnd();

             }
     }
     glColor3f (0, 1, 0);
     glBegin (GL_LINE_STRIP);
     int max=0;
     for (i=0; i<cell.stat.size(); i++)
     {
             if (cell.stat[i]>max) max=cell.stat[i];
     }
     for (i=0; i<cell.stat.size(); i++)
     {
             glVertex2i (160+1.6*i, 160+160*cell.stat[i]/max);
     }
     glEnd();
 }

